package cn.edu.neusoft.maxingxin231.yuejian06.Fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Activity.PostDetailActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Activity.PostPicActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.PostAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.PostBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.LoginListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.PostModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class PostFragment extends BaseFragment {
    RecyclerView recyclerview;
    ImageButton btn_put;

    private List<PostBean> items;
    ListListener<PostBean> postBeanListListener = new ListListener<PostBean>() {
        @Override
        public void onResponse(List<PostBean> list) {
            items = list;
            PostAdapter postAdapter = new PostAdapter(getActivity(),items,R.layout.post_card);
            recyclerview.setAdapter(postAdapter);
            recyclerview.setItemAnimator(new DefaultItemAnimator());

        }

        @Override
        public void onFail(String msg) {

        }
    };



    @Override
    protected void initView() {
        recyclerview = (RecyclerView) view.findViewById(R.id.recyclerview);
        LinearLayoutManager layoutLayoutManager=new LinearLayoutManager(getActivity());
        recyclerview.setLayoutManager(layoutLayoutManager);
        layoutLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);


    }

    @Override
    void initEvent() {
        PostModel postModel = new PostModel();
        postModel.getPostList(postBeanListListener);

    }

    @Override
    void initData() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_post);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}
